package com.offcn.com.offcn.strings;
/*
判断一个数是不是回文串
 */

import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = sc.nextLine();

        System.out.println(isPalindrome(str));
        System.out.println(isPalindrome(str, 3, 8));
    }

    private static boolean isPalindrome(String str) {
        if(str == null || str.length() == 0) {
            return false;
        }
        for (int i = 0; i <str.length() ; i++) {
            if(str.charAt(i) != str.charAt(str.length() -1 - i)) {
                return false;
            }
        }
        return true;
    }
    //判断指定范围的字符串是否是回文串
    public static boolean isPalindrome(String str,int beginIndex,int endIndex) {

        if(str == null || str.length() == 0 || beginIndex > endIndex) {
            return false;
        }
        System.out.println(str.substring(beginIndex, endIndex));
        while (beginIndex < endIndex) {
            if(str.charAt(beginIndex) == str.charAt(endIndex)) {
                return false;
            }
            beginIndex++;
            endIndex--;
        }
        return true;
    }
}
